<template>
  <div class="container">
    <div class="container-title">
      <p>部门计划</p>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>招商管理</el-breadcrumb-item>
        <el-breadcrumb-item>招商计划</el-breadcrumb-item>
        <el-breadcrumb-item>部门计划</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="search-box">
      <el-form ref="form" :model="searchData">
        <el-form-item
          ><el-input
            v-model="searchData.planName"
            placeholder="计划名称"
          ></el-input>
        </el-form-item>
        <div class="block">
          <el-date-picker
            v-model="searchData.date"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </div>
        <el-form-item>
          <el-select
            v-model="searchData.status"
            filterable
            placeholder="是否达标"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            type="success"
            @click="onSearch"
            icon="el-icon-search"
            style="background-color: #0bb197"
            >查询</el-button
          ><el-button @click="onReset" icon="el-icon-refresh" class="reset"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 表格 -->
    <div class="data-list">
      <div class="data-list-title">
        <span>查询结果列表</span>
        <el-button type="success" style="background-color: #0bb197"
          ><a @click="exportExcel">导出</a></el-button
        >
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="planName" label="计划名称" align="center">
        </el-table-column>
        <el-table-column prop="startDate" label="开始日期" align="center">
        </el-table-column>
        <el-table-column prop="endDate" label="结束日期" align="center">
        </el-table-column>
        <el-table-column prop="planMaker" label="执行人" align="center">
        </el-table-column>
        <el-table-column prop="deptName" label="执行部门" align="center">
        </el-table-column>
        <el-table-column
          prop="planComplete"
          label="计划完成目标"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="planType" label="计划类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.planType == 0">意向登记</span>
            <span v-if="scope.row.planType == 1">意向协定</span>
            <span v-if="scope.row.planType == 2">合同签批</span>
            <span v-if="scope.row.planType == 3">企业入住</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="actuallyComplete"
          label="已完成目标"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="actuallyPercentage"
          label="已完成占比"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="planState" label="是否达标" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.planType == 0">否</span>
            <span v-if="scope.row.planType == 1">是</span>
          </template>
        </el-table-column>
      </el-table>
      <!-- 页码 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :background="true"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      pageNum: 1,
      pageSize: 5,
      total: 0,
      currentPage: 1,
      options: [
        {
          value: '0',
          label: '否',
        },
        {
          value: '1',
          label: '是',
        },
      ],
      searchData: { planName: '', date: [] },
      tableData: [],
    };
  },
  methods: {
    //渲染
    getData: function () {
      this.$axios({
        url: '/smart/investment/myplan/query',
        method: 'post',
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
        },
        data: {
          startDate: this.searchData.date[0],
          endDate: this.searchData.date[1],
          planName: this.searchData.planName,
        },
      }).then(({ data }) => {
        if (data.code == '00000') {
          if (data.data.list.length > 0) {
            this.tableData = data.data.list;
            this.total = data.data.total;
          } else {
            this.tableData = data.data.list;
            this.$message.error('暂无数据！');
          }
        } else {
          this.$message.error(data.msg);
        }
      });
    },
    //搜索
    onSearch: function () {
      this.getData();
    },
    //重置
    onReset: function () {
      this.searchData = {
        planName: '',
        date: [],
      };
      this.getData();
    },
    //页码
    handleSizeChange(val) {
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getData();
    },

    // 导出
    exportExcel() {
      // 使用outerHTML属性获取整个table元素的HTML代码（包括<table>标签），然后包装成一个完整的		HTML文档，设置charset为urf-8以防止中文乱码
      var html =
        "<html><head><meta charset='utf-8' /></head><body>" +
        document.querySelector('.el-table').outerHTML +
        '</body></html>';
      // 实例化一个Blob对象，其构造函数的第一个参数是包含文件内容的数组，第二个参数是包含文件类型属性	  的对象
      var blob = new Blob([html], { type: 'application/vnd.ms-excel' });
      //这里也可以通过指定id进行获取
      var a = document.getElementsByTagName('a')[0];
      // 利用URL.createObjectURL()方法为a元素生成blob URL
      a.href = URL.createObjectURL(blob);
      // 设置文件名
      a.download = '我的计划' + '.xls';
    },
  },
  mounted: function () {
    this.getData();
  },
};
</script>

<style lang="less" scoped>
.container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  .container-title {
    width: 98%;
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    p {
      color: #333333;
      font-size: 16px;
      font-weight: 400;
      font-family: 'Arial Normal', 'Arial';
    }
    .el-breadcrumb-item {
      color: rgba(148, 148, 148, 0.898039215686275);
      font-size: 12px;
      font-weight: 400;
      font-family: 'Arial Normal', 'Arial';
    }
  }
  .search-box {
    width: 98%;
    height: 80px;
    background: #ffffff;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    border: 1px solid #ffffff;
    border-radius: 5px;
    .el-form {
      width: 98%;
      background: #ffffff;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      .el-form-item {
        margin-left: 10px;
        margin-bottom: 0;
        .el-select {
          width: 155px;
        }
        .el-button {
          margin: 10px;
        }
        .reset {
          background-color: white;
          color: #c0c4cc;
          border: 1px solid #c0c4cc;
        }
        .reset:hover {
          color: #0bb197;
        }
      }
      .block {
        margin-left: 10px;
      }
      .el-date-editor--datetimerange.el-input__inner {
        width: 310px;
      }
    }
  }
  .data-list {
    width: 98%;
    height: 100%;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-around;
    margin-top: 20px;
    .data-list-title {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      span {
        height: 16px;
        font-family: 'Arial Normal', 'Arial';
        font-weight: 700;
        font-style: normal;
        font-size: 13px;
        color: #3c4145;
      }
    }
    .el-table {
      flex: 1;
      .el-button {
        color: #0bb197;
      }
    }
    .el-pagination {
      width: 98%;
      height: 60px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  }
}
</style>
<style>
.el-pagination.is-background .el-pager li:not(.disabled):hover {
  color: #0bb197;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #0bb197;
  color: #fff;
}
a {
  text-decoration: none;
  color: white;
}
</style>
